package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizGradeLog;
import com.member.shop.domain.SysBizIntegralConfig;
import com.member.shop.service.ISysBizGradeLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【等级变动记录】控制器
 *
 * @author wangxin
 * @version 1.0
 * @date 2024-06-13
 **/
@RestController
@RequestMapping("/shop/gradeLog")
public class SysBizGradeLogController extends BaseController {
    @Resource
    private ISysBizGradeLogService sysBizGradeLogService;
    private void setTenantId(SysBizGradeLog sysBizGradeLog) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizGradeLog.setTenantId(tenantId);
        }
    }
    /**
     * 查询等级变动记录列表
     */
    @PreAuthorize("@ss.hasPermi('shop:gradeLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizGradeLog sysBizGradeLog) {
        startPage();
        setTenantId(sysBizGradeLog);
        List<SysBizGradeLog> list = sysBizGradeLogService.selectSysBizGradeLog(sysBizGradeLog);
        return getDataTable(list);
    }

    /**
     * 导出等级变动记录列表
     */
    @PreAuthorize("@ss.hasPermi('shop:gradeLog:export')")
    @Log(title = "等级变动记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizGradeLog sysBizGradeLog) {
 setTenantId(sysBizGradeLog);
        List<SysBizGradeLog> list = sysBizGradeLogService.selectSysBizGradeLogList(sysBizGradeLog);
        ExcelUtil<SysBizGradeLog> util = new ExcelUtil<SysBizGradeLog>(SysBizGradeLog.class);
        util.exportExcel(response, list, "等级变动记录数据");
    }

    /**
     * 获取等级变动记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:gradeLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizGradeLogService.selectSysBizGradeLogById(id));
    }

    /**
     * 新增等级变动记录
     */
    @PreAuthorize("@ss.hasPermi('shop:gradeLog:add')")
    @Log(title = "等级变动记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizGradeLog sysBizGradeLog) {
        return toAjax(sysBizGradeLogService.insertSysBizGradeLog(sysBizGradeLog));
    }

    /**
     * 修改等级变动记录
     */
    @PreAuthorize("@ss.hasPermi('shop:gradeLog:edit')")
    @Log(title = "等级变动记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizGradeLog sysBizGradeLog) {
        return toAjax(sysBizGradeLogService.updateSysBizGradeLog(sysBizGradeLog));
    }

    /**
     * 删除等级变动记录
     */
    @PreAuthorize("@ss.hasPermi('shop:gradeLog:remove')")
    @Log(title = "等级变动记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizGradeLogService.deleteSysBizGradeLogByIds(ids));
    }
}
